<?php
/**
 * IG_Product_Notice_Adapter_Db
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Db.php 586 2011-05-31 10:07:18Z mmxie $
 */
class IG_Product_Notice_Adapter_Db extends IG_Product_Notice_Abstract
{
    /**
     *
     * @var Zend_Db_Adapter_Abstract
     */
    protected $_adapter = null;

    public function __construct($config)
    {
        if ($config['product_id'] == 2) {
            $wsdl = 'http://zxy.iwgame.com/service/game-card/do/key/m1yvPFJJiHT8Mcjiuzai?wsdl';
        } else {
            $wsdl = 'http://sm.iwgame.com/service/game-card/do/key/m1yvPFJJiHT8Mcjiuzai?wsdl';
        }
        $client = new SoapClient($wsdl);
        $group = $client->dbConfig($config['product_id'], $config['zone_id'], $config['group_id']);
        $dbConfig = $group[0]['db'];

        unset($config['host']);
        $this->_config = $config;
        $this->_adapter = Zend_Db::factory($dbConfig['adapter'], $dbConfig);
    }

    /**
     * 发送
     */
    public function send()
    {
        if ($this->_adapter) {
            $table = $this->_config['table'];
            $this->_adapter->insert($table, $this->_config['bind']);
            return true;
        }
        return false;
    }
}